<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改部门变动人员')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form id="form-depChange-edit" class="form-horizontal" AUTOCOMPLETE="OFF">
        <input name="id" id="id" type="hidden" th:value="${depChangeEmp.id}"/>
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">工号：</label>
                    <div class="col-sm-8">
                        <input name="badge" id="badge" th:value="${depChangeEmp.badge}" class="form-control"
                               readonly="readonly" type="text"/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">姓名：</label>
                    <div class="col-sm-8">
                        <input name="name" id="name" class="form-control" th:value="${depChangeEmp.name}"
                               readonly="readonly" type="text"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">公司名称：</label>
                    <div class="col-sm-8">
                        <input name="CompId" id="CompId" th:value="${depChangeEmp.compName}" readonly="readonly"
                               class="form-control" type="text"/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">部门名称：</label>
                    <div class="col-sm-8">
                        <input name="DepId" id="DepId" class="form-control" th:value="${depChangeEmp.depName}"
                               readonly="readonly" type="text"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">工作岗位：</label>
                    <div class="col-sm-8">
                        <input name="jobName" id="jobName" th:value="${depChangeEmp.jobName}" readonly="readonly"
                               class="form-control" type="text"/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">员工状态：</label>
                    <div class="col-sm-8">
                        <input name="empStatusName" id="empStatusName" class="form-control"
                               th:value="${depChangeEmp.empStatusName}" readonly="readonly" type="text"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">入职日期：</label>
                    <div class="col-sm-8">
                        <input name="joindate" id="joindate" th:value="${depChangeEmp.joindate}" readonly="readonly"
                               class="form-control" type="text"/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">工作城市：</label>
                    <div class="col-sm-8">
                        <input name="WorkCityTitle" id="WorkCityTitle" class="form-control"
                               th:value="${depChangeEmp.WorkCityTitle}" readonly="readonly" type="text"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">员工类型：</label>
                    <div class="col-sm-8">
                        <input name="empTypeName" id="empTypeName" th:value="${depChangeEmp.empTypeName}"
                               readonly="readonly" class="form-control" type="text"/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">行政上级：</label>
                    <div class="col-sm-8">
                        <input name="ReportToName" id="ReportToName" class="form-control"
                               th:value="${depChangeEmp.ReportToName}" readonly="readonly" type="text"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">职能上级：</label>
                    <div class="col-sm-8">
                        <input name="WfReportToName" id="WfReportToName" th:value="${depChangeEmp.WfReportToName}"
                               readonly="readonly" class="form-control" type="text"/>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">变动信息</h4>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>新公司名称：</label>
                    <div class="col-sm-8">
                        <select id="newCompId" name="newCompId" class="form-control" th:onchange="getbumen(this.value)"
                                required>
                            <option value="">请选择</option>
                            <option th:each="company:${companys}"
                                    th:value="${company.compID}" th:text="${company.title}"
                                    th:selected="${depChangeEmp.newCompid==company.compID}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>新部门名称：</label>
                    <div class="col-sm-8">
                        <select name="newDepid" id="newDepid" class="form-control" th:onchange="getgangwei(this.value)">
                            <option value="">请选择</option>
                            <option th:each="odepartment:${departments}" th:value="${odepartment.DepID}"
                                    th:selected="${depChangeEmp.newDepid==odepartment.DepID}"
                                    th:text="${odepartment.title}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>新工作岗位：</label>
                    <div class="col-sm-8">
                        <select name="newJobid" id="newJobid" class="form-control m-b">
                            <option value="">请选择</option>
                            <option th:each="job:${jobs}" th:value="${job.jobID}"
                                    th:selected="${depChangeEmp.newJobid==job.jobID}"
                                    th:text="${job.title}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">新员工类型：</label>
                    <div class="col-sm-8">
                        <input name="newEmpTypeTitle" id="newEmpTypeTitle" th:value="${depChangeEmp.empTypeName}"
                               readonly="readonly" class="form-control" type="text"/>
                        <input name="newEmpType" id="newEmpType" th:value="${depChangeEmp.emptype}" class="form-control"
                               type="hidden"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>新工作城市：</label>
                    <div class="col-sm-8">
                        <input name="NewWorkcityName" id="NewWorkcityName"  onclick="getNewWorkCity()" th:value="${depChangeEmp.NewWorkcityName}"
                               type="text"
                               class="form-control" required />
                        <input name="newworkcity" id="newworkcity" th:value="${depChangeEmp.newworkcity}" type="hidden"
                               class="form-control">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">新直接上级：</label>
                    <div class="col-sm-8">
                        <input name="NewReportToName" id="NewReportToName" th:value="${depChangeEmp.NewReportToName}" onclick="getNewReportTo()"
                               type="text"
                               class="form-control">
                        <input name="NewReportTo" id="NewReportTo" th:value="${depChangeEmp.NewReportTo}" type="hidden"
                               class="form-control">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">新职能上级：</label>
                    <div class="col-sm-8">
                        <input name="NewWfReportToName" id="NewWfReportToName" onclick="getNewWFReportTo()"
                               th:value="${depChangeEmp.NewWfReportToName}" type="text"
                               class="form-control">
                        <input name="NewWfReportTo" id="NewWfReportTo" th:value="${depChangeEmp.NewWfReportTo}"
                               type="hidden" class="form-control">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>调动类型：</label>
                    <div class="col-sm-8">
                        <select name="orgchangetype" id="orgchangetype" class="form-control m-b"
                                th:with="type=${@dict.getType('eCD_OrgChangeType')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:selected="${depChangeEmp.orgchangetype+'' == dict.dictValue}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>调动原因：</label>
                    <div class="col-sm-8">
                        <select name="orgchangeReason" id="orgchangeReason" class="form-control m-b"
                                th:with="type=${@dict.getType('eCD_OrgChangeReason')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:selected="${depChangeEmp.orgchangeReason+'' == dict.dictValue}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>生效日期：</label>
                    <div class="col-sm-8">
                        <input name="EffectDate" id="EffectDate" th:value="${depChangeEmp.EffectDate}" type="text"
                               class="form-control laydate-demo-1" required />
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>发薪公司：</label>
                    <div class="col-sm-8">
                        <select id="salarycomp" name="salarycomp" class="form-control">
                            <option value="">请选择</option>
                            <option th:each="company:${companys}"
                                    th:value="${company.compID}" th:text="${company.title}"
                                    th:selected="${depChangeEmp.salarycomp==company.compID}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">备注：</label>
                    <div class="col-sm-8">
                        <input name="Remark" id="Remark" th:value="${depChangeEmp.Remark}" type="text"
                               class="form-control" />
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js"/>

<script th:inline="javascript">

    var prefix = ctx + "changeManage/DepChange";

    $(function () {
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '.laydate-demo-1',
                type: 'date'
            });
        });
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-depChange-edit").serializeArray();
            var id = $("#id").val();
            //下拉框校验
            var newCompId = $("#newCompId").val();
            var newDepid = $("#newDepid").val();
            var newJobid = $("#newJobid").val();
            var newEmpType = $("#newEmpType").val();
            var newworkcity = $("#newworkcity").val();
            var NewReportTo = $("#NewReportTo").val();
            var NewWfReportTo = $("#NewWfReportTo").val();
            var orgchangetype = $("#orgchangetype").val();
            var orgchangeReason = $("#orgchangeReason").val();
            var EffectDate = $("#EffectDate").val();
            var Remark = $("#Remark").val();
            var salarycomp = $("#salarycomp").val();
            if (newCompId == "" || newCompId == null) {
                $.modal.alertWarning("请选择新公司!");
                return;
            } else if (newDepid == "" || newDepid == null) {
                $.modal.alertWarning("请选择新部门!");
                return;
            }else if (newJobid == "" || newJobid == null) {
                $.modal.alertWarning("请选择新岗位!");
                return;
            }else if (newworkcity == "" || newworkcity == null) {
                $.modal.alertWarning("请选择新工作城市!");
                return;
            }else if (orgchangetype == "" || orgchangetype == null) {
                $.modal.alertWarning("请选择调动类型!");
                return;
            }else if (orgchangeReason == "" || orgchangeReason == null) {
                $.modal.alertWarning("请选择调动原因!");
                return;
            }else if (EffectDate == "" || EffectDate == null) {
                $.modal.alertWarning("请选择生效日期!");
                return;
            }else if (salarycomp == "" || salarycomp == null) {
                $.modal.alertWarning("请选择发薪公司!");
                return;
            }

            data.push({"name": "id", "value": id});
            data.push({"name": "newCompId", "value": newCompId});
            data.push({"name": "newDepid", "value": newDepid});
            data.push({"name": "newJobid", "value": newJobid});
            data.push({"name": "newEmpType", "value": newEmpType});
            data.push({"name": "newworkcity", "value": newworkcity});
            data.push({"name": "NewReportTo", "value": NewReportTo});
            data.push({"name": "NewWfReportTo", "value": NewWfReportTo});
            data.push({"name": "orgchangetype", "value": orgchangetype});
            data.push({"name": "orgchangeReason", "value": orgchangeReason});
            data.push({"name": "EffectDate", "value": EffectDate});
            data.push({"name": "Remark", "value": Remark});
            data.push({"name": "salarycomp", "value": salarycomp});
            $.operate.save(prefix + "/edit", data);
        }
    }

    function getbumen(value) {
        var html = "";
        $.ajax({
            async: false,
            url: ctx + "empentry/findDep",
            data: {
                "compID": value
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#newDepid").empty();
                var arry = data;
                html += "<option value=''>请选择</option>";
                for (var i = 0; i < arry.length; i++) {
                    html += "<option value='"
                        + arry[i].depID
                        + "'>"
                        + arry[i].title
                        + "</option>";
                }
                $("#newDepid").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function getgangwei(value) {
        var html = "";
        $.ajax({
            async: false,
            url: ctx + "empentry/findJob",
            data: {
                "DepID": value
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#newJobid").empty();
                var arry = data;
                html += "<option value=''>请选择</option>";
                for (var i = 0; i < arry.length; i++) {
                    html += "<option value='"
                        + arry[i].jobID
                        + "'>"
                        + arry[i].title
                        + "</option>";
                }
                $("#newJobid").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }


    function getNewReportTo() {
        $.modal.open("选择新直接上级", prefix + "/getNewReportTo?type=ReportTo");
    }

    function getNewWFReportTo() {
        $.modal.open("选择新职能上级", prefix + "/getNewReportTo?type=WFReportTo");
    }

    function getNewWorkCity() {
        $.modal.open("选择新工作城市", prefix + "/getNewWorkCity");
    }

</script>
</body>
</html>
